// pages/second/second.js
Page({
    data: {
      finishTime: null,
      startTime: null,
      timeDifference: {
        minutes: '00',
        seconds: '00',
        milliseconds: '00'
      }
    },
  
    onLoad: function (options) {
      // 获取传递过来的完成时间
      const finishTime = options.finishTime;
      if (finishTime) {
        this.setData({ 
          finishTime: new Date(finishTime),
          startTime: new Date() // 记录进入 second 页面的时间
        });
        this.calculateTimeDifference();
      }
  
      // 每隔一段时间更新当前时间差异
      setInterval(() => {
        this.calculateTimeDifference();
      }, 10);
    },
  
    calculateTimeDifference: function () {
      const { finishTime, startTime } = this.data;
  
      if (finishTime && startTime) {
        const difference = finishTime - startTime;
  
        let minutes = Math.floor((difference % (1000 * 60 * 60)) / (1000 * 60));
        let seconds = Math.floor((difference % (1000 * 60)) / 1000);
        let milliseconds = Math.floor((difference % 1000) / 10);
  
        // 确保时间值为两位数
        minutes = this.twoDigits(minutes);
        seconds = this.twoDigits(seconds);
        milliseconds = this.twoDigits(milliseconds);
  
        this.setData({
          timeDifference: {
            minutes,
            seconds,
            milliseconds
          }
        });
      }
    },
  
    twoDigits: function (num) {
      return num.toString().padStart(2, '0');
    },
  
    onReady: function () {
      // 初始化数据
    }
  });